package com.rjs.serialization;

import java.io.IOException;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class XmlSerializer implements ISerializer {
	
	private static final XStream xstream = new XStream(new DomDriver()); 

	public byte[] serialize(Object obj) throws IOException {
		return xstream.toXML(obj).getBytes();
	}

	@SuppressWarnings("unchecked")
	public <T> T deserialize(byte[] buf, Class<T> clzz) throws IOException, ClassNotFoundException {
		String xml = new String(buf);
		return (T)xstream.fromXML(xml);
	}

}
